<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    linux常用命令 |  柒点的晚风
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/warehouse/favicon.ico" />
  
  
<link rel="stylesheet" href="/warehouse/css/main.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

  

</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-linux常用命令" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  linux常用命令
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/warehouse/2020/11/12/linux%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" class="article-date">
  <time datetime="2020-11-12T11:42:08.000Z" itemprop="datePublished">2020-11-12</time>
</a>
      
      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.3k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">5分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h3 id="1-终端的打开方式"><a href="#1-终端的打开方式" class="headerlink" title="1.终端的打开方式"></a><strong>1.终端的打开方式</strong></h3><p>①ctrl+alt+t</p>
<p>②直接点击图标</p>
<p>③打开一个终端后，再打开一个新的终端ctrl+shift+n</p>
<p>关闭终端：命令行中输入exit然后按回车</p>
<p>放大 ctrl+shift+ ‘+’</p>
<p>缩小 ctrl+‘-’</p>
<h3 id="2-有关ls的命令"><a href="#2-有关ls的命令" class="headerlink" title="2.有关ls的命令"></a><strong>2.有关ls的命令</strong></h3><p>ls 显示当前目录下的文件和文件夹</p>
<p>ls  -l显示当前目录下文件或文件夹的属性</p>
<p>ls  -lh按照文件大小单位来显示</p>
<p>ls  -a显示所有文件包括隐藏文件（隐藏文件是以.开头的）</p>
<p>目录中一个点 代表当前目录，..两个点代表上一级目录</p>
<h3 id="3-有关cd的命令"><a href="#3-有关cd的命令" class="headerlink" title="3.有关cd的命令"></a><strong>3.有关cd的命令</strong></h3><p>cd  目录名  进入目录如果目录名称过长，可以输入前几个字母后使用tab键或esc键将其补齐。</p>
<p>cd ..  是返回上一级目录</p>
<p>cd -  返回上一次操作的目录</p>
<p>cd ~ 返回当前用户的家目录（cd后面什么都不加，也可以实现）</p>
<p>cd / 打开根目录</p>
<h3 id="4-有关pwd的命令"><a href="#4-有关pwd的命令" class="headerlink" title="4.有关pwd的命令"></a><strong>4.有关pwd的命令</strong></h3><p>​      pwd ：打印当前目录位置</p>
<h3 id="5-创建文件"><a href="#5-创建文件" class="headerlink" title="5.创建文件"></a><strong>5.创建文件</strong></h3><p>​      如果文件不存在就创建空的普通文件</p>
<p>​      touch 文件名   touch  yapingnihao </p>
<p>​      如果文件存在就更新文件的时间戳，不会改变文件的内容</p>
<p>​        第一次touch    -rw-rw-r– 1 linux linux    6 六月 15 15:38 yapingnihao  </p>
<p>​        第二次touch    -rw-rw-r– 1 linux linux    6 六月 15 15:39 yapingnihao</p>
<h3 id="6-mkdir：-创建目录"><a href="#6-mkdir：-创建目录" class="headerlink" title="6. mkdir： 创建目录"></a><strong>6. mkdir： 创建目录</strong></h3><p>​      mkdir   jiaweinihao 在当前目录创建一个jiaweinihao的目录</p>
<p>​      创建的目录不可以和文件和文件夹重名</p>
<p>​     mkdir  d1  d2  d3 可以创建多个目录，这些目录是在同一级的</p>
<p>​      mkdir -p  1/2/3     创建具备层级关系的1 2 3这些目录</p>
<h3 id="7-删除目录"><a href="#7-删除目录" class="headerlink" title="7.删除目录"></a><strong>7.删除目录</strong></h3><p>​    remove  directory</p>
<p>​    rmdir只能用来删除空目录</p>
<h3 id="8-rm命令（remove）"><a href="#8-rm命令（remove）" class="headerlink" title="8.rm命令（remove）"></a><strong>8.rm命令（remove）</strong></h3><p>​    rm  1.c  删除当前目录下的1.c</p>
<p>   rm *.c 删除所有以.c结尾的文件（  *是通配符，表示所有）</p>
<p>   删除目录 ：</p>
<p>   rm -r  1   删除1目录（-r递归删除）</p>
<p>   rm test* -rf （-f强制删除）</p>
<p>   rm * -rf   删除所有的当前目录下文件文件夹</p>
<h3 id="9-复制命令cp（拷贝）"><a href="#9-复制命令cp（拷贝）" class="headerlink" title="9.复制命令cp（拷贝）"></a><strong>9.复制命令cp（拷贝）</strong></h3><p>​    <strong>复制文件：</strong></p>
<p>   复制不改名cp    源文件的路径/名字    目标路径</p>
<p>   cp    ../../a.c     3/   将上上目录中的a.c文件，复制到3这个目录中，</p>
<p>   复制并改名   cp    源文件的路径/名字    目标路径/新名字</p>
<p>   cp    test/a.c     3/4/b.c    将test目录中的a.c复制到3/4/目录后命名为b.c</p>
<p>   <strong>复制目录：</strong></p>
<p>​    cp  路径/原目录   目标路径   -r （递归拷贝）</p>
<p>​    cp  路径/原目录   目标路径/新名   -r  复制并重命名</p>
<h3 id="10-echo打印命令"><a href="#10-echo打印命令" class="headerlink" title="10.echo打印命令"></a><strong>10.echo打印命令</strong></h3><p> echo  helloworld   将helloworld打印在终端上</p>
<p> echo  helloworld &gt; a.c 将helloworld输出重定向到a.c文件中（覆盖之前a.c的内容）</p>
<p> echo  helloworld &gt;&gt; a.c将helloworld输出重定向到a.c文件中（追加在文件内容的末尾，不覆盖）</p>
<h3 id="11-进程的相关命令"><a href="#11-进程的相关命令" class="headerlink" title="11.进程的相关命令"></a><strong>11.进程的相关命令</strong></h3><p>ps命令用于查看当前正在运行的进程，最常用的方法是ps aux，然后再通过管道使用grep命令过滤查找特定的进程，再对特定的进程进行操作，其中grep起到搜索作用。</p>
<p>ps -ef | grep java 表示查看所有进程里CMD是java的进程信息</p>
<p>ps -aux | grep java -aux显示所有状态</p>
<p>kill -9 [PID]    用kill命令终止进程<strong>，</strong>-9表示强迫进程立即停止</p>
<h3 id="12-重命名"><a href="#12-重命名" class="headerlink" title="12.重命名"></a><strong>12.重命名</strong></h3><p>mv  有移动和重命名的作用</p>
<h3 id="13-防火墙命令"><a href="#13-防火墙命令" class="headerlink" title="13.防火墙命令"></a>13.防火墙命令</h3><h4 id="查看-firewall-版本"><a href="#查看-firewall-版本" class="headerlink" title="查看 firewall 版本"></a>查看 firewall 版本</h4><p>$ firewall-cmd –version</p>
<h4 id="查看-firewall状态"><a href="#查看-firewall状态" class="headerlink" title="查看 firewall状态"></a>查看 firewall状态</h4><p>$ firewall-cmd –state  </p>
<h4 id="查看端口及服务信息"><a href="#查看端口及服务信息" class="headerlink" title="查看端口及服务信息"></a>查看端口及服务信息</h4><p>列出打开的所有端口：firewall-cmd  –list-ports</p>
<p>列出打开的所有服务：firewall-cmd  –list-services</p>
<p>firewall-cmd –add-service=http  #暂时开放http</p>
<p> firewall-cmd –permanent –add-service=http（ssh） #永久开放http（ssh）</p>
<p> firewall-cmd –zone=public –add-port=80/tcp –permanent #在public中永久开放80端口</p>
<p> firewall-cmd –permanent –zone=public –remove-service=ssh  #从public zone中永久移除服务</p>
<p> firewall-cmd –reload  #重新加载配置</p>
<p>systemctl restart firewalld  #重启firewalld服务，使配置生效/可查</p>
<p>firewall-cmd –zone=public –add-port=80/tcp –permanent  #开放80 端口</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">命令含义：</span><br><span class="line"></span><br><span class="line">--zone #作用域</span><br><span class="line"></span><br><span class="line">--add-port&#x3D;80&#x2F;tcp #添加端口，格式为：端口&#x2F;通讯协议</span><br><span class="line"></span><br><span class="line">--permanent  #永久生效，没有此参数重启后失效</span><br></pre></td></tr></table></figure>

<h3 id="14systemctl命令的使用"><a href="#14systemctl命令的使用" class="headerlink" title="14systemctl命令的使用"></a>14systemctl命令的使用</h3><p>Centos7 服务设置命令 systemctl 用法 （替代service 和 chkconfig）</p>
<p>Centos7 systemd服务，systemd是服务管理程序，他整合了service和chkconfig的功能为一体，可以永久性或只在当前会话中启用/禁用服务。</p>
<p>列出所有可用单元：systemctl list-unit-files</p>
<p>列出所有运行中单元：systemctl list-units</p>
<p>启动一个服务：systemctl start httpd（firewalld）</p>
<p>关闭一个服务：systemctl stop httpd</p>
<p>重启一个服务：systemctl restart httpd</p>
<p>显示一个服务的状态：systemctl status httpd</p>
<p>开机启动一个服务：systemctl enable httpd</p>
<p>开机禁止一个服务：systemctl disable httpd</p>
<p>查看服务是否开启启动: systemctl is-enabled httpd</p>
<p>查看已启动的服务列表：systemctl list-unit-files | grep enabled</p>
<p>查看启动失败的服务列表：systemctl –failed</p>

      
      <!-- reward -->
      
      <div id="reward-btn">
        打赏
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>版权声明： </strong s>
              本博客所有文章除特别声明外，均采用 <a href="https://www.apache.org/licenses/LICENSE-2.0.html" rel="external nofollow"
                target="_blank">Apache License 2.0</a> 许可协议。转载请注明出处！
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://gitee.com/hyfgyy/warehouse.git/2020/11/12/linux%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      

    </footer>

  </div>

  
  
  <nav class="article-nav">
    
    
      <a href="/warehouse/2020/11/11/vim%E7%9A%84%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">vim的相关命令.md</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: '',
        app_key: '',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020
        柒点的晚风
      </li>
      <li>
        
        Powered by
        
        
        <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src=''></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
    <aside class="sidebar">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/warehouse/"><img src="/warehouse/images/touxiang.jpg" alt="柒点的晚风"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/warehouse/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/warehouse/archives">归档</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/warehouse/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>需要帮助吗~</p>
  <div class="reward-box">
    
    
    <div class="reward-item">
      <img class="reward-img" src="/warehouse/warehouse/images/weixin.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/warehouse/js/jquery-2.0.3.min.js"></script>


<script src="/warehouse/js/share.js"></script>


<script src="/warehouse/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/warehouse/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/warehouse/js/ayer.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>



<script src="/warehouse/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.2/dist/jquery.fancybox.min.css">
<script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.2/dist/jquery.fancybox.min.js"></script>


    
  </div>
</body>

</html>